import logging

from rest_framework.authentication import BasicAuthentication
from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response

logger = logging.getLogger(__name__)


@permission_classes((IsAuthenticated,))
@authentication_classes((BasicAuthentication,))
@api_view(http_method_names=['GET'])
def get_api_view(request: Request):
    logger.info('' + str(request.query_params))
    return Response({
        'text': 'Hello World',
        'user': 'Hello Admin',
    })


@api_view(http_method_names=['POST'])
def post_api_view(request: Request):
    logger.info('request.data:' + str(request.data))
    return Response({
        'text': 'Hello World',
        'user': 'Hello Admin',
    })


@api_view(http_method_names=['POST'])
def form_api_view(request: Request):
    # form表单post请求使用request.POST返回QueryDict
    logger.info('request.data:' + str(request.data))
    return Response({
        'text': 'Hello World',
        'user': 'Hello Admin',
    })
